package com.zmn.plat.admin.controller.servcategory;

import javax.servlet.http.HttpServletRequest;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.plat.common.exception.PlatException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.zmn.common.constant.StatusConsts;
import com.zmn.common.dto.ResultDTO;
import com.zmn.plat.business.interfaces.servcategory.ShowCategoryAssociationBService;

/**
 * @author linfeng
 * @version v1.0
 * @since 2019/09/23 9:15
 * @类说明：前台服务分类、前台产品分类关联功能
 */
@Controller
@RequestMapping("/serv/showCateg/relate/")
public class ShowCategoryAssociationModifyController extends ServCategoryBaseController {
    private Logger logger = LoggerFactory.getLogger(ShowCategoryAssociationModifyController.class);

    @Autowired
    private ShowCategoryAssociationBService showCategoryAssociationBService;

    @PostMapping(value = "batchRelateBackCategory")
    @ResponseBody
    public ResponseDTO batchRelateBackCategory(HttpServletRequest request, @RequestBody JSONObject object) {
        if (null == object) {
            return ResponseDTO.fail(StatusConsts.STATUS_ERROR, "请检查参数是否正确！");
        }

        try {
            showCategoryAssociationBService.batchRelateBackCategory(getMcStaffRealName(), object);
            return ResponseDTO.success(true,"提交成功");
        }catch (PlatException e){
            return ResponseDTO.fail(e.getMessage());
        }catch (Exception e){
            logger.error("batchRelateBackCategory error.",e);
            return ResponseDTO.fail("提交失败");
        }

    }
}
